# study code
#
# FibBuzz
# http://codnote.net/2011/10/13/fibbuzz/
#
# start  2011/10/10 
# parser 2011/10/10
# end    2011/10/10 




class FibonacciGenerator
    attr_reader :n

    def initialize
        @n = 0
        @fn0 = 0
        @fn1 = 0
    end

    def next
        ret = (n < 2) ? @n : @fn0 + @fn1
        @fn0 = @fn1
        @fn1 = ret
        @n+=1
        return ret
    end

end



def fibBuzz( n )
    fib = FibonacciGenerator.new
    while fib.n < n do
        fn = fib.next
        fizz = (fn % 3) == 0
        buzz = (fn % 5) == 0

        if(fizz && buzz)
            puts "FizzBuzz"
        elsif(fizz)
            puts "Fizz"
        elsif(buzz)
            puts "Buzz"
        else
            puts fn
        end
    end
end

def fibBuzz2( n )
    if( n < 2)
        putsFizzBuzz n
        return n
    end
    fn0 = fibBuzz2( n - 2)
    fn1 = fibBuzz2( n - 1 )
    fn = fn1 + fn0
    putsFizzBuzz n
    return n
end

def putsFizzBuzz( v )
    fizz = (v % 3) == 0
    buzz = (v % 5) == 0

    if(fizz && buzz)
        puts "FizzBuzz"
    elsif(fizz)
        puts "Fizz"
    elsif(buzz)
        puts "Buzz"
    else
        puts v
    end
end

fibBuzz( 100 )
